Clarify interface requirements for supports_inplace and similar#103
Conversation
The `similar` function must return a "mutable" array, but not necessarily one that returns `true` for `supports_inplace`. Instead, `ArrayInterface.ismutable` seems like a more sensible check.
The expectation is that we can use in-place operators for abstract arrays that are both mutable and can for which write access is efficient. The `ArrayInterface` package provides traits for this.
There was a problem hiding this comment.
Pull request overview
This PR fixes an incorrect fallback for the supports_inplace interface function by delegating to ArrayInterface.ismutable and ArrayInterface.fast_scalar_indexing instead of using Base.ismutabletype, which incorrectly returns false for wrapper types like Hermitian{ComplexF64, Matrix{ComplexF64}} that do support in-place operations.
Changes:
- Updated
supports_inplacefallback to useArrayInterface.ismutable(T) && ArrayInterface.fast_scalar_indexing(T)forAbstractArraytypes - Changed validation in
check_stateandcheck_operatorto useArrayInterface.ismutableinstead ofsupports_inplacewhen checkingsimilar()results - Added comprehensive test for Hermitian matrices to verify the fix
- Updated documentation to clarify interface requirements and added ArrayInterface references
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
Project.toml |
Added ArrayInterface 7.0 as a dependency |
docs/Project.toml |
Added ArrayInterface for documentation |
docs/make.jl |
Added ArrayInterface documentation link |
test/Project.toml |
Added ArrayInterface for tests |
src/interfaces/supports_inplace.jl |
Updated fallback to use ArrayInterface functions and improved documentation |
src/interfaces/supports_matrix_interface.jl |
Clarified that setindex! is not required for matrix interface |
src/interfaces/state.jl |
Changed validation to use ArrayInterface.ismutable and fixed typo in documentation |
src/interfaces/operator.jl |
Changed validation to use ArrayInterface.ismutable and clarified documentation |
test/test_operator_linalg.jl |
Added test for Hermitian matrix in-place support |
test/test_invalid_interfaces.jl |
Updated error message expectations to match new validation approach |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
As pointed out by GitHub Copilot in code review
ac88cc4 to
356d684
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #103 +/- ##
========================================
+ Coverage 90.2% 90.2% +0.1%
========================================
Files 35 35
Lines 2551 2550 -1
========================================
Hits 2299 2299
+ Misses 252 251 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Delegate to
ArrayInterface.Closes #102